package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface dishMapper {
    /**
     * 根据分类id返回菜品
     *
     * @param id
     * @return
     */
    @Select("select count(*) from dish where category_id=#{id}")
    public Integer cheakById(Integer id);

    /**
     * 添加菜品
     *
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insertDish(Dish dish);


    /**
     * 根据id返回菜品信息
     *
     * @param name
     * @return
     */
    @Select("select * from dish where id=#{ID}")
    Dish getDish(Integer ID);

    /**
     * 分页查询
     *
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVO> select(DishPageQueryDTO dishPageQueryDTO);

    @Select("select * from dish where id=#{id}")
    DishVO selectById(int id);

    @AutoFill(value = OperationType.UPDATE)
    void update(Dish dish);

    void delete(ArrayList<Integer> id);

    @AutoFill(value = OperationType.UPDATE)
    @Update("update dish set status=#{status},update_time=#{updateTime},update_user=#{updateUser} where id=#{id}")
    void set(Dish dish);


    @Select("select * from dish where category_id=#{categoryId}")
    List<Dish> selectByCategoryId(Integer categoryId);
}
